/**
 * Created by ZFL on 2017/9/26.
 */
var vm=new Vue({
    el:'#store',
    data:{
        goodsList:[],   //店铺商品列表
        userPicture:'', //用户头像
        suggestedPrice:0,
        nickName:'',
        storeUserId:''
    },


})
Vue.filter('price',function(value){
    return divideNumber(value,100);
})
function appInit(){
    PageInit();
}
function PageInit(){
    perInfo();
    infiniteSroll();
    storeInfo();

}
var userId=$.getPara('storeUserId');
vm.storeUserId=$.getPara('storeUserId');
var pageSize=10;
var pageNum=1;
var loading=false;
var userGoodsId=0;
var pageCount='';

//滚动加载信息

//滚动加载
loading = false;
function infiniteSroll() {
    $("body").infinite().on("infinite", function () {
        if (loading) return;
        loading = true;
        pageNum++;
        $('.weui-infinite-scroll-box').show();
        setTimeout(function () {
            loading = false;
            $('.weui-infinite-scroll-box').hide();
            storeInfo();
        }, 1500);   //模拟延迟
    });
}


function storeInfo(){
    $.ajaxHandler({
        model:function(){
            var obj={};
            obj.userId=userId;
            obj.pageNum=pageNum;
            obj.pageSize=pageSize;
            return obj;
        },
        visibleTime: 0,
        visible:'show',
        dataType: "json",
        approve:true,
        api: '/yg_baijiaappgoods/goods/myStore',
        success:function(res){
            if(res.code===10000){
                var data=res.data;
                pageCount=data.goodsList.length;
                if(data.goodsList.length > 0){
                    data.goodsList.forEach(function(val,ind){
                        vm.goodsList.push(val);

                    })
                    //vm.goodsList=data.goodsList;
                    vm.userPicture=data.userPicture;
                    // 加载数据
                    loading = false;


                }else {
                    $(document.body).destroyInfinite();
                }

            }else{
                YDUI.dialog.toast(res.message, 'error', 1000);
            }
        }
    })
}



function perInfo(){
    $.ajaxHandler({
        model:function(){
            var obj={};
            obj.userId=userId;

            return obj;
        },
        visibleTime: 0,
        visible:'show',
        dataType: "json",
        approve:true,
        api: 'yg_baijiaapp/user/getUserEntityByIdNoPassword',
        success:function(res){
            if(res.code===10000){
                var data=res.data;
               vm.nickName=data.nickName;

            }else{
                YDUI.dialog.toast(res.message, 'error', 1000);
            }
        }
    })
}
